<template>
  <div class="my-page bg-c2">
    <div class="myheaderbox">
      <div class="headerlogo">
        <img src="../../assets/img/photo.png">
      </div>
      <div style="display:flex; justify-content: center;align-items:center">
        <h5 id="nick_name" class="fs20 c1">{{mydata.nickName}}</h5>
        <span class="fs16 c7" v-if="mydata.realFlag">【节点商】</span>
      </div>
      <h2 id="user_name" class="fs16">{{mydata.userName}}</h2>
    </div>
    <div class="mycontentbox">
      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>GIC资产</p>
          <span @click="doWithdraw(1)" class="c3">GIC提现</span>
        </div>
        <div class="ul-wrap">
          <ul>
            <li>
              <h3>锁仓数量</h3>
              <p id="integral">{{gicData.integral ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>可提数量</h3>
              <p id="can_extract_amount">{{gicData.canExtractAmount ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>已提数量</h3>
              <p id="withdraw_amount">{{gicData.withdrawAmount ||0 | twoFloat}}</p>
            </li>
            <!-- <li>
              <h3>{{balanceDay|fetchDay}}日余额</h3>
              <p id="integral">{{DayDealData.yesterdayAmount ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>{{yesterday | fetchDay}}日买入量</h3>
              <p id="can_extract_amount">{{DayDealData.amountBuy ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>{{yesterday | fetchDay}}日卖出量</h3>
              <p id="withdraw_amount">{{DayDealData.amountSell ||0 | twoFloat}}</p>
            </li> -->
            <!-- <li>
              <h3>{{yesterday | fetchDay}}日新增持仓量</h3>
              <p id="integral">{{DayDealData.beforeTrans || 0 | twoFloat}}</p>
            </li>-->
            <li>
              <h3>{{beforDay2 | fetchDay}}日持仓</h3>
              <p>{{DayDealData.yesterdayAmount ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>{{beforDay1 | fetchDay}}日持仓</h3>
              <p>{{DayDealData.dayBalance ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>买入数量</h3>
              <p>{{DayDealData.amountBuy || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>卖出数量</h3>
              <p>{{DayDealData.amountSell || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>应释放量</h3>
              <p id="can_extract_amount">{{DayDealData.releaseAmount || 0 |twoFloat}}</p>
            </li>
            <li class="help">
              <h3>状态</h3>
              <p id="withdraw_amount">{{$consts.MAPS.VERIFY[DayDealData.verify] || '未释放' }}</p>
            </li>
            <li>
              <router-link to="my/rule">
                <b class="fs14 c3" style="font-weight:normal">释放规则</b>
              </router-link>
            </li>
          </ul>
        </div>
      </div>
      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>推广收益</p>
          <router-link to="my/group">
            <P class="c3">查看团队</P>
          </router-link>
        </div>
        <div class="ul-wrap">
          <ul>
            <li>
              <h3>团队</h3>
            </li>
            <li>
              <h3>一级</h3>
            </li>
            <li>
              <h3>二级</h3>
            </li>
            <li>
              <h3>人数</h3>
            </li>
            <li>
              <span>{{release[0].pnum_one || 0}}</span>
            </li>
            <li>
              <span>{{release[0].pnum_too|| 0}}</span>
            </li>
            <li class="help">
              <h3>待释放贡献</h3>
            </li>
            <li>
              <span>{{release[1].verify_total_one || 0 | twoFloat}}</span>
            </li>
            <li>
              <span>{{release[1].verify_total_too || 0 | twoFloat}}</span>
            </li>
            <li>
              <router-link to="my/contribute">
                <b>贡献规则</b>
              </router-link>
            </li>
            <!-- <li>
              <router-link to="my/copywriting">
                <b>文案信息</b>
              </router-link>
            </li>-->
          </ul>
        </div>
      </div>
      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>节点收益</p>
          <span @click="doWithdraw(3)" class="c3">USDT提现</span>
        </div>
        <div class="item-bottom-wrap">
          <ul>
            <li>
              <h2>节点人数</h2>
              <span>{{nodeData.pnum || 0 }}</span>
            </li>
            <li>
              <h2>节点商数</h2>
              <span>{{nodeData.totalreleasenum || 0 }}</span>
            </li>
            <li>
              <h2>USDT收益</h2>
              <span>{{nodeData.integral || 0 | twoFloat}}</span>
            </li>
            <li>
              <h2>USDT可提数</h2>
              <span>{{nodeData.dayreleasenum || 0 | twoFloat}}</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="quit-wrap">
      <button class="quitbtn" @click="logout()">安全退出</button>
    </div>
  </div>
</template>

<script>
import * as z from "@/utils/com.js";
import * as r from "@/utils/validate.js";
import { parseTime } from "@/utils/com.js";

export default {
  onLoad(){
    console.log(this.DayDealData.releaseTime);
    
  },
  created() {
    this.mydata = JSON.parse(this.$auth.get()["localdata"]);
    if (this.mydata.userType !== 1) {
      this.logout();
    }
    this.getUserInfo(); //用户信息
    this.getReleaseData(); //释放收益
    this.getGicData(); //GIC
    this.getDayDeal(); //当日交易量
    this.getNodeData(); //节点收益
  },
  data() {
    return {
      mydata: {},
      gicData: [{}],
      DayDealData: {},
      nodeData: {},
      release: [{}, {}, {}, {}]
    };
  },
  computed: {
    // yesterday: function() {
    //   let curDate = new Date();
    //   let preDate = new Date(curDate.getTime() - 24 * 60 * 60 * 1000); //前一天
    //   let preDateRes = parseTime(preDate);
    //   return preDateRes.substring(0, 10);
    // },
    // balanceDay: function() {
    //   let curDate = new Date();
    //   let preDate = new Date(curDate.getTime() - 24 * 60 * 60 * 1000 * 2);
    //   let preDateRes = parseTime(preDate);
    //   return preDateRes.substring(0, 10);
    // }
    beforDay1(){
      if(this.DayDealData.releaseTime){
        return this.DayDealData.releaseTime
      }
    },
    beforDay2(){
      if(this.DayDealData.releaseTime){
          let preDateRes =  new Date(this.DayDealData.releaseTime).getTime() - 24 * 60 * 60 * 1000
          return parseTime(preDateRes).substring(0, 10);
      }
    }
  },
  methods: {
    doWithdraw(kindId) {
      let reg = /^[0-9](\.\d+)?/;
      z.prompt("请输入您需要提现的数量", async val => {
        if (!reg.test(val.value)) {
          z.alert("请输入正确的数字");
          return;
        }
        let response = await this.$http.post(
          "/bus/withdraw/do",
          this.$qs.stringify({
            userId: JSON.parse(localStorage.getItem("localdata")).uuid,
            amount: val.value,
            withdrawType: kindId
          })
        );
        z.alert(response.data.msg);
      });
    },

    logout() {
      this.$auth.logout();
      window.location.href = "/auth/login/logout";
    },

    async getReleaseData() {
      let response = await this.$http.post(
        "/sys/partner/parreport",
        this.$qs.stringify({
          userId: this.mydata.uuid
        })
      );
      if (200 == response.data.code) {
        this.release = response.data.data;
      } else {
        z.alert(response.data.msg);
      }
    },
    async getGicData() {
      let gicRes = await this.$http.post(
        "/bus/account/getaccount",
        this.$qs.stringify({
          accountType: 1
        })
      );
      if (200 == gicRes.data.code && gicRes.data.data) {
        this.gicData = gicRes.data.data;
      }
    },
    async getDayDeal() {
      let DayDealRes = await this.$http.post(
        "/bus/release/releaseday",
        this.$qs.stringify({
          releaseType: 1
        })
      );
      if (DayDealRes.data.code == 200 && DayDealRes.data.data) {
        this.DayDealData = DayDealRes.data.data;
      }
    },
    async getNodeData() {
      let nodeRes = await this.$http.post(
        "/sys/partner/nodereport",
        this.$qs.stringify({
          currencyId: 3
        })
      );
      if (nodeRes.data.code == 200) {
        this.nodeData = nodeRes.data.data;
      }
    },
    async getUserInfo() {
      let userRes = await this.$http.post(
        "/sys/user/curinfo",
        this.$qs.stringify({})
      );
      this.userInfo = userRes.data.data;
    }
  },
  mounted() {
    setInterval(val => {
      this.getUserInfo();
      this.getGicData();
      if (!this.userInfo) {
        this.logout();
      }
    }, 20000);
  }
};
</script>
<style lang="scss" scoped src="./styles/index.scss">
</style>

